import modal from './modal.vue'

const MyPlugin = {}
MyPlugin.install = function (Vue, options) {
    let arr = []

    // const Comp = Vue.extend(modal)
    // const vm = new Comp({
    //     data: {
    //         defaultPosition: '',
    //         defaultType: '',
    //         defaultTimeout: ''
    //     }
    // }).$mount()

    // console.log(vm)
    // document.body.appendChild(vm.$el)

    // Vue.prototype.$myPlugin = {
    //     addModal(type, msg){
    //         vm.addModal(type, msg)
    //     },
    //     close(){
    //         vm.close()

    //     }
    // }

    Vue.prototype.$showModel = function ({ title, component, closeFun}){
        const Comp = Vue.extend(modal)
        let zIndex = 99 + arr.length
        let width, height, top, left;
        switch (size) {
            case "min":
                width = 300;
                height = 260;
                break;
            case "middle":
                width = 500;
                height = 400;
                break;
            case "max":
                width = 800;
                height = 500;
                break;
            default:
                width = 200;
                height = 260;
                break;
        }
        top = parseInt(window.innerHeight / 2) + this.list.length * 30 - (height / 2);
        left = parseInt(window.innerWidth / 2) + this.list.length * 30 - (width / 2);
        const vm = new Comp({
            props: {
                title: ''
                width,
                height,
                top,
                left,
                zIndex,
                component

            },

        }).$mount()

        vm.$on('close', (...opt) => {
            closeFun(opt)
        })

        vm.$on('confirmClose', (...opt) => {
            arr.slice(uid, 1)
        })        

        console.log(vm)

        arr.push({
            index: zIndex,
            vm: vm,
            uid: arr.length
        })

        document.body.appendChild(vm.$el)

        return vm;
    }


}

export default MyPlugin
